package com.example.shaidemo;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.w3c.dom.Text;

/**
 * A simple {@link Fragment} subclass.
 *
 * create an instance of this fragment.
 */
public class MineFragment extends Fragment {

    TextView nameView,accountView;
    String name,account;

    public MineFragment() {
        // Required empty public constructor
    }



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =  inflater.inflate(R.layout.fragment_mine, container, false);
        nameView =(TextView)view.findViewById(R.id.name_view);

//        //修改个人信息
//        Bundle bundle = getArguments();
//        String newName = bundle.getString("newName");
//        nameView.setText(newName);

        //查看上传记录
        TextView upload = (TextView)view.findViewById(R.id.upload_label) ;
        upload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(getActivity(),UploadActivity.class);
                startActivity(intent);
            }
        });

        //查看浏览记录
        TextView look = (TextView)view.findViewById(R.id.look_label) ;
        look.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(getActivity(),BrowseActivity.class);
                startActivity(intent);
            }
        });

        //修改个人信息
        TextView config = (TextView)view.findViewById(R.id.personal_label);
        accountView = (TextView)view.findViewById(R.id.account_view);
        config.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = nameView.getText().toString();
                String account = accountView.getText().toString();
                //需传入个人的信息
                Intent intent =new Intent(getActivity(),ConfigPersonalActivity.class);
                intent.putExtra("name",name);
                intent.putExtra("account",account);
                startActivityForResult(intent,1);
            }
        });

        //查看收藏记录
        TextView collect = (TextView)view.findViewById(R.id.collect_label) ;
        collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(getActivity(),CollectActivity.class);
                startActivity(intent);
            }
        });

        //查看平台条款
        TextView clause = (TextView)view.findViewById(R.id.clause_label);
        clause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(getActivity(),ClauseActivity.class);
                startActivity(intent);
            }
        });

        return view;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if(requestCode==1 && resultCode == 2){
            //修改个人信息
            String newName = data.getStringExtra("newName");
            nameView.setText(newName);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}